﻿#include <iostream>
#include <string>
using namespace std;


std::cout << "Hello World!\n";
CURL* curl;
CURLcode statusCode;
string htmlData;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
    // 设置要抓取的⽹⻚地址
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_URL, "https://ssr1.scrape.center");
    // 设置回调函数，⽤于处理获取到的响应数据
    
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &htmlData);
    // 
    执⾏
        HTTP
        请求
        auto res = curl_easy_perform(curl);
    if (res != CURLE_OK) {
        std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(r
            es) << std::endl;
    }
    // 
    输出获取到的⽹⻚内容
        //std::cout << htmlData << std::endl;
         /*fstream out("html.txt");
               out << htmlData;
               out.close();*/
        vector<string> vt = getTagsOfA(htmlData);
    /*for (int i = 0; i < vt.size(); ++i) {
              cout << vt[i] << endl;
          }*/
          // 
    清理
        CURL
        实例
        curl_easy_cleanup(curl);
}
else {
    std::cerr << "curl_easy_init() failed." << std::endl;
    return 1;
}
// 
清理
libcurl
curl_global_cleanup();
回调函数：
3
C++
size_t writeCallback(void* contents, size_t size, size_t nmemb, std::string * o
    utput) {
    size_t totalSize = size * nmemb;
    output->append((char*)contents, totalSize);
    return totalSize;
}
